package com.run.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.run.common.annotation.Log;
import com.run.common.core.controller.BaseController;
import com.run.common.core.domain.AjaxResult;
import com.run.common.enums.BusinessType;
import com.run.merchant.domain.RunUserAddress;
import com.run.merchant.service.IRunUserAddressService;
import com.run.common.utils.poi.ExcelUtil;
import com.run.common.core.page.TableDataInfo;

/**
 * 用户地址信息Controller
 * 
 * @author run
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/merchant/infoaddress")
public class RunUserAddressController extends BaseController
{
    @Autowired
    private IRunUserAddressService runUserAddressService;

    /**
     * 查询用户地址信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(RunUserAddress runUserAddress)
    {
        startPage();
        List<RunUserAddress> list = runUserAddressService.selectRunUserAddressList(runUserAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:export')")
    @Log(title = "用户地址信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RunUserAddress runUserAddress)
    {
        List<RunUserAddress> list = runUserAddressService.selectRunUserAddressList(runUserAddress);
        ExcelUtil<RunUserAddress> util = new ExcelUtil<RunUserAddress>(RunUserAddress.class);
        util.exportExcel(response, list, "用户地址信息数据");
    }

    /**
     * 获取用户地址信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(runUserAddressService.selectRunUserAddressById(id));
    }

    /**
     * 新增用户地址信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:add')")
    @Log(title = "用户地址信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RunUserAddress runUserAddress)
    {
        return toAjax(runUserAddressService.insertRunUserAddress(runUserAddress));
    }

    /**
     * 修改用户地址信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:edit')")
    @Log(title = "用户地址信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RunUserAddress runUserAddress)
    {
        return toAjax(runUserAddressService.updateRunUserAddress(runUserAddress));
    }

    /**
     * 删除用户地址信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infoaddress:remove')")
    @Log(title = "用户地址信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(runUserAddressService.deleteRunUserAddressByIds(ids));
    }
}
